import React from "react";
import Util from "../../../../../util/Util";
import Packapply from '../../Packapply';
import './css/contract_management.css';


export default class Supply extends React.Component {
    constructor(props) {
        super(props);
        this.state = {

        };

    }

    //签订合同附件
    signedContractUrl(){
      let signedContractUrl = [];
      let signedContractUrlSum = [];
      if (this.props.order.signedContractUrl1) {
        signedContractUrl.push(Util.signedContractStr(this.props.order.signedContractUrl1))
        signedContractUrlSum.push(this.props.order.signedContractUrl1)
      }
      if (this.props.order.signedContractUrl2) {
        signedContractUrl.push(Util.signedContractStr(this.props.order.signedContractUrl2))
        signedContractUrlSum.push(this.props.order.signedContractUrl2)
      }
      if (this.props.order.signedContractUrl3) {
        signedContractUrl.push(Util.signedContractStr(this.props.order.signedContractUrl3))
        signedContractUrlSum.push(this.props.order.signedContractUrl3)
      }
      if (this.props.order.signedContractUrl4) {
        signedContractUrl.push(Util.signedContractStr(this.props.order.signedContractUrl4))
        signedContractUrlSum.push(this.props.order.signedContractUrl4)
      }
      if (this.props.order.signedContractUrl5) {
        signedContractUrl.push(Util.signedContractStr(this.props.order.signedContractUrl5))
        signedContractUrlSum.push(this.props.order.signedContractUrl5)
      }
      this.signedContractUrlx = signedContractUrl ? signedContractUrl : [];
      return this.signedContractUrlx.map((item2,index)=>{
          return(
              <Packapply oArr={item2} item2={item2} contractUrlSum={signedContractUrlSum[index]}/>
          )
      })
    }

    downloadPdf() {
        let paymentJSON = JSON.parse(this.props.order.paymentJSON);
        window.open(paymentJSON.url)
    }

    render() {
        const a1 = this.props.order && this.props.order.status == 4 && this.props.order.paymentJSON;
        return(
          <div className="supplementary_contract_box">
              <ul>
                <li>
                  <span>合同编号 :</span>
                  <p>{this.props.order.signedContract}</p>
                </li>
                <li>
                  <span>合同附件 :</span>
                  <p style={{float:'left',width:'950px',fontSize:'14px', color: '#333'}}>
                    {
                        this.signedContractUrl() == '' ? '无' : this.signedContractUrl()
                    }
                  </p>
                </li>
                  <li>
                      <span>签订时间 :</span>
                      <p>{Util.dateFormat(this.props.order.signedDate)}</p>
                  </li>
                  {
                      a1 ? (
                          <li>
                              <span style={{width: 96}}>代付款协议 :</span>
                              <p>{JSON.parse(this.props.order.paymentJSON).contractNumber} &nbsp;<a className="supplementary_contract_box_download" onClick={this.downloadPdf.bind(this)}>下载</a></p>
                          </li>
                      ) : null
                  }

              </ul>
          </div>
        )
    }
}
